<?php
/*
	$department_id = $karyawan_id->department_id;
	$karyawan_name=$karyawan_id->name;
	$karyawan_id=$karyawan_id->id;	
	$setx=0;
 if ((isset($_GET["department_id"])) or (isset($_GET["tahun_ajaran_id"]))) 
 	{	
	if ($_GET["tahun_ajaran_id"]>0){
 		$tahun_ajaran_id = Yii::app()->request->getParam("tahun_ajaran_id","");		
		$actTahunAjaran = MTahunAjaran::model()->findAll("id='".$tahun_ajaran_id."' order by id");
		$tahun_ajaran_name=$actTahunAjaran[0]["name"];
		$tahun_ajaran_id=$actTahunAjaran[0]["id"];	
		$start_date = $actTahunAjaran[0]["start_date"];
		$end_date = $actTahunAjaran[0]["end_date"];	
		$setx=0;
		}
		else
		{$setx=1;}
	}
	else
		{$setx=1;}
	if 	($setx==1)			
	{  	
		$actTahunAjaran = CMTahunAjaran::getTahunAjaranActive($department_id);	
		$tahun_ajaran_name=$actTahunAjaran["name"];
		$tahun_ajaran_id=$actTahunAjaran["id"];	
		$start_date = $actTahunAjaran["start_date"];
		$end_date = $actTahunAjaran["end_date"];		
 	}	
	*/
?>

<script>
	
	function reloadPage(){		
		$("#tblData").jqGrid("setGridParam",{postData:{"semester_id" :$("#semester_id").val(),"pelajaran_id" :$("#pelajaran_id").val(),"tahun_ajaran_id" :$("#tahun_ajaran_id").val(),"kelas_tahun_ajaran_id" :$("#kelas_tahun_ajaran_id").val()},datatype:"json"}).trigger("reloadGrid",[{current:true}]);
		$("#idSrcTblData").val("");
	}
	
	function newData(){
		var url="index.php?r=karyawan/pelajaran/task_detail/form&op=add&semester_id=" + $("#semester_id").val()+"&pelajaran_id=" + $("#pelajaran_id").val()+"&kelas_tahun_ajaran_id=" + $("#kelas_tahun_ajaran_id").val();
		var winName = "Form Process";
		var specs ="menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0";
		var width=450,height=300;
		var replace = false,onCenter = true;
		var w = openWindow(winName,url,width,height,onCenter,specs,replace);
		w.focus();
		var timer = setInterval(function() {   
			if(w.closed) {  
				clearInterval(timer);  
				reloadPage();
			}  
		}, 1000);
	}
	
	function closeTest(){
		
	}
	
	function editRow(id){		
		var url="index.php?r=karyawan/pelajaran/task_detail/form&op=edit&id=" + id;
		var winName = "Form Process";
		var specs ="menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0";
		var width=450,height=300;
		var replace = true,onCenter = true;
		var w = openWindow(winName,url,width,height,onCenter,specs,replace);
		w.focus();
		var timer = setInterval(function() {   
			if(w.closed) {  
				clearInterval(timer);  
				reloadPage();
			}  
		}, 1000);
	}
	
	function deleteRow(id){
		if (confirm("Delete data ?")){			
			window.parent.showLoader();			
			var data = $("#tblData").jqGrid("getRowData",id);
			var editUrl = $("#tblData").jqGrid("getGridParam","editUrl");			
			$.ajax({	
				url : editUrl,
				type:"GET",
				async:true,
				data: {op: "del",id:data.id},
				success: function(data) {
					if(data.actionStatus == 1){
						alert(data.actionMessage);
					}						
				},
				complete:function(){
					window.parent.hideLoader();
				}
			});			
			$("#tblData").jqGrid("delRowData",id);
		}
	}

 
		
	$(function(){
		var pelajaran_id =$("#pelajaran_id").val();
		var kelas_tahun_ajaran_id =$("#kelas_tahun_ajaran_id").val();
		var semester_id =$("#semester_id").val();				
		var numberTemplate = {formatter: 'number', align: 'right', sorttype: 'number'};	 
		$("#tblData").jqGrid({
			url:'index.php?r=karyawan/pelajaran/task_detail/detailList',
			editUrl:'index.php?r=karyawan/pelajaran/task_detail/edit',
			postData:{"pelajaran_id":pelajaran_id,"kelas_tahun_ajaran_id":kelas_tahun_ajaran_id,"semester_id":semester_id},
			datatype: 'json',
			loadonce:true,
			mtype:"GET",
			autowidth:true,
			height:"100%",
			altRows:true,
			ignoreCase:true,
			colNames: ['id','Task Date','Task Name','Task Pelajaran Detail', 'notes', 'Status','Action'],
			colModel: [
				{name: 'id', index: 'id', width: 40,hidden:false,sorttype:'int',formatter:'int'},
				{name: 'task_date', index: 'task_date', width: 0 },				 
				{name: 'task_name', index: 'task_name', width: 140,search:true},
				{name: 'name', index: 'name', width: 140,search:true},
				{name: 'notes', index: 'notes'},
				{name: 'is_active', index: 'is_active', width: 30, align: 'center', formatter: 'checkbox'},
				{name: 'act', index: 'act', width: 40, align: 'center'},
				
			],
			gridview: true,
			rownumbers: false,
			rowNum: 10,
			rowList: [5, 10, 15],
			pager: '#navTblData',
			viewrecords: true,
			caption: 'Task Pelajaran Detail',
			jsonReader : { 
				root:"model",
				repeatitems: false			
			},
			loadComplete:function(data){
				console.log(data);
			},
			gridComplete: function(){ 
				var ids = jQuery("#tblData").getDataIDs(); 
				for(var i=0;i<ids.length;i++){ 
					var cl = ids[i]; 
					//btnEdit = "<input style='height:22px;width:20px;' type='button' value='E' onclick=jQuery('#rowed2').editRow("+cl+"); ></ids>"; 
					//btnDelete = "<input style='height:20px;width:20px;' type='button' value='S' onclick=jQuery('#rowed2').saveRow("+cl+"); />"; 
					btnEdit = "<img title='edit' class='imgBtn' style='height:20px;width:20px;' src='images/action/Actions-Edit-icon.png' onclick='editRow(" + cl + ")' />"; 
					btnDelete = "<img title='delete' class='imgBtn' style='margin-left:5px;height:20px;width:20px;' src='images/action/Actions-Delete-icon.png' onclick='deleteRow(" + cl + ")' />"; 
					jQuery("#tblData").setRowData(ids[i],{act:btnEdit+btnDelete}) 
				} 
			}
		});
		$("#tblData").jqGrid('navGrid','#navTblData',{add:false,edit:false,search:false,del:false,refresh:false});
		
		//add search text
		$("#tblData").jqGrid('addSearchText',["name","notes"]);
	});
</script>

<div style="">
	<script>
	 
function Department_OnChange_fill_all(){ 
	window.parent.showLoader();	
		$filter = {"is_active":1,"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"tahun_ajaran_id",title_field:"tahun_ajaran_name",group:"tahun_ajaran_id"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#tahun_ajaran_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		
					
		$filter = {"is_active":1,"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"MSemester",filter: $filter,value_field:"id",title_field:"name"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#semester_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		
		$filter = {"is_active":1,"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"tingkatan_id",title_field:"tingkatan_name",group:"tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#tingkatan_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});		
				
		$filter = {"is_active":1,"tingkatan_id":$("#tingkatan_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"kelas_tahun_ajaran_id",title_field:"kelas_name",group:"kelas_id,tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#kelas_tahun_ajaran_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		 
		$filter = {"is_active":1,"karyawan_id":$("#karyawan_id").val(),"tingkatan_id":$("#tingkatan_id").val(),"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
	 
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"pelajaran_id",title_field:"pelajaran_name"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#pelajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			 
}	

function Tahun_Ajaran_OnChange_fill_all(){ 
	window.parent.showLoader();	
		$filter = {"is_active":1,"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"MSemester",filter: $filter,value_field:"id",title_field:"name"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#semester_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		
		$filter = {"is_active":1,"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"tingkatan_id",title_field:"tingkatan_name",group:"tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#tingkatan_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});		
				
		$filter = {"is_active":1,"tingkatan_id":$("#tingkatan_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"kelas_tahun_ajaran_id",title_field:"kelas_name",group:"kelas_id,tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#kelas_tahun_ajaran_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		 
		$filter = {"is_active":1,"karyawan_id":$("#karyawan_id").val(),"tingkatan_id":$("#tingkatan_id").val(),"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
	 
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"pelajaran_id",title_field:"pelajaran_name"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#pelajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			 
}			


function Tingkatan_OnChange_fill_Task_Detail(){ 
	window.parent.showLoader();	
		$filter = {"is_active":1,"tingkatan_id":$("#tingkatan_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"kelas_tahun_ajaran_id",title_field:"kelas_name",group:"kelas_id,tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#kelas_tahun_ajaran_id",data);	
//				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		 
		$filter = {"is_active":1,"karyawan_id":$("#karyawan_id").val(),"tingkatan_id":$("#tingkatan_id").val(),"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
	 
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"pelajaran_id",title_field:"pelajaran_name"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#pelajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			 
}		
 
 
 

function  KelasTahunAjaran_OnChange_fill_Task_Detail(){ 
	window.parent.showLoader();	
		$filter = {"is_active":1,"karyawan_id":$("#karyawan_id").val(),"tingkatan_id":$("#tingkatan_id").val(),"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
	 
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"pelajaran_id",title_field:"pelajaran_name"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#pelajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			 
} 
/*	
		$(function(){
			$("#department_id").change(function(){
				var	department_id=$("#department_id").val();
				var	pelajaran_id=$("#pelajaran_id").val();			
				var	semester_id=$("#semester_id").val();
				var	tahun_ajaran_id=$("#tahun_ajaran_id").val();
				var	task_pelajaran_id=$("#task_pelajaran_id").val();														
				window.location.replace("index.php?r=KarTaskPelajaran_Detail&pelajaran_id="+pelajaran_id+"&department_id="+department_id+"&tahun_ajaran_id="+tahun_ajaran_id+"&task_pelajaran_id="+task_pelajaran_id+"&semester_id="+semester_id);
			});
		});		
		
		$(function(){
			$("#semester_id").change(function(){
			*/
				/*var	department_id=$("#department_id").val();
				var	pelajaran_id=$("#pelajaran_id").val();		
				var	semester_id=$("#semester_id").val();								
				window.location.replace("index.php?r=KarTaskPelajaran_Detail&pelajaran_id="+pelajaran_id+"&department_id="+department_id+"&task_pelajaran_id="+task_pelajaran_id+"&semester_id="+semester_id);*/
/*			
				reloadPage();
			});
		});
		$(function(){
			$("#pelajaran_id").change(function(){
	var	department_id=$("#department_id").val();
				var	pelajaran_id=$("#pelajaran_id").val();			
				var	semester_id=$("#semester_id").val();
				var	tahun_ajaran_id=$("#tahun_ajaran_id").val();
				var	task_pelajaran_id=$("#task_pelajaran_id").val();														
				window.location.replace("index.php?r=KarTaskPelajaran_Detail&pelajaran_id="+pelajaran_id+"&department_id="+department_id+"&tahun_ajaran_id="+tahun_ajaran_id+"&task_pelajaran_id="+task_pelajaran_id+"&semester_id="+semester_id);
			});
		});	
		$(function(){
			$("#task_pelajaran_id").change(function(){
				reloadPage();
			});
		});				
		*/	
	</script>

		
<div>

 <div>
 		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Department") ?></label>	
		<select name="department_id" id="department_id" onchange="Department_OnChange_fill_all()"   >
			<?php
				foreach ($departments as $department){
					$selected = $department_id == $department["department_id"] ? "selected" : "";				
					echo"<option value='$department[department_id]' $selected  >$department[department_id]</option>";
				}
			?>
		</select> 
</div>        
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Tahun Ajaran") ?></label>	
		<select name="tahun_ajaran_id" id="tahun_ajaran_id" onChange="Tahun_Ajaran_OnChange_fill_all()">
			<?php
				foreach ($tahunAjarans as $tahunAjaran){
					$selected = $tahun_ajaran_id == $tahunAjaran["tahun_ajaran_id"] ? "selected" : "";				
					echo"<option value='$tahunAjaran[tahun_ajaran_id]' $selected>$tahunAjaran[tahun_ajaran_name]</option>";
				}
			?>
		</select>
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Semester") ?></label>	
		<select name="semester_id" id="semester_id"   onchange="reloadPage()"   >
			<?php
				foreach ($semesters as $semester){
					$selected = $semester_id == $semester["id"] ? "selected" : "";				
					echo"<option value='$semester[id]' $selected>$semester[name]</option>";
				}
			?>
		</select>
	</div>	
 	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Tingkatan") ?></label>	
		<select name="tingkatan_id" id="tingkatan_id"   onchange="Tingkatan_OnChange_fill_Task_Detail()"  >
			<?php
				foreach ($tingkatans as $tingkatan){
					$selected = $tingkatan_id == $tingkatan["tingkatan_id"] ? "selected" : "";				
					echo"<option value='$tingkatan[tingkatan_id]' $selected>$tingkatan[tingkatan_name]</option>";
				}
			?>
		</select>
	</div>       
           
  	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Kelas") ?></label>	
		<select name="kelas_tahun_ajaran_id" id="kelas_tahun_ajaran_id"   onchange="KelasTahunAjaran_OnChange_fill_Task_Detail()"  >
			<?php
				foreach ($kelass as $kelas){
					$selected = $kelas_tahun_ajaran_id == $kelas["kelas_tahun_ajaran_id"] ? "selected" : "";				
					echo"<option value='$kelas[kelas_tahun_ajaran_id]' $selected>$kelas[kelas_name]</option>";
				}
			?>
		</select>
	</div>       
     
  
  	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Pelajaran") ?></label>	
 		<select name="pelajaran_id" id="pelajaran_id"  onchange="reloadPage()"   >
			<?php
				foreach ($pelajarans as $pelajaran){
					$selected = $pelajaran_id == $pelajaran["id"] ? "selected" : "";				
					echo"<option value='$pelajaran[id]' $selected>$pelajaran[name]</option>";
				}
			?>
		</select>
	</div>   
               
	<div style="float:rigth">
	<?php 
		$this->widget('application.components.widgets.ActionBar', 
			array("menuAlign" => "right", 
				'items' => array(
					array(
						'id' => "btnRefresh",
						'title' => Yii::t("menu","Segarkan"),
						'icon' => "images/action/Action-Refresh-icon.png",
						'callback'=>"reloadPage"
					),					
					array(
						'id' => "btnNew",
						'title' => Yii::t("menu","Baru"),
						'icon' => "images/action/Actions-document-new-icon.png",
						'callback'=>"newData"
					),
					array(
						'id' => "btnNew",
						'title' => Yii::t("menu","Cetak"),
						'icon' => "images/action/Actions-document-print-icon2.png",
						'callback'=>"printData"
					),					
					
				)
			)
		);
	?>
	</div>	
	<div style="clear:both"></div>	
	<table id="tblData"><tr></tr></table>
	<div id="navTblData"></div>
</div>